package de.silvalauinger.objectclassmapper.schema;

import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.toArray;
import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.ldap.model.schema.registries.Schema;
import org.apache.directory.shared.ldap.model.schema.registries.SchemaLoader;
import org.apache.directory.shared.ldap.schemaloader.JarLdifSchemaLoader;
import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;

public final class DefaultSchemaManagerFactory {

    //<editor-fold defaultstate="collapsed" desc="Constants">
    public final static SchemaManager SCHEMA_MANAGER;

    static {
        try {
            final SchemaLoader schemaLoader = new JarLdifSchemaLoader();
            SCHEMA_MANAGER = new DefaultSchemaManager(schemaLoader);
            // load all schemas (including disabled)
            SCHEMA_MANAGER.loadDisabled(toArray(schemaLoader.getAllSchemas(), Schema.class));
        } catch (final Exception exception) {
            throw propagate(exception);
        }
    }
    //</editor-fold>
}